﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

namespace Prism.Core.Audio.DirectSound
{
    public static class AudioFileReader
    {
        public static WaveStream GetInputStream(Stream source)
        {
            object reader;
            WaveStream inputStream;

            bool isWaveFormat;
            reader = new WaveFileReader(source, out isWaveFormat);
            if (isWaveFormat == true)
            {
                try
                {
                    reader = new WaveFileReader(source);
                    inputStream = new WaveChannel32(reader as WaveFileReader);
                }
                catch (ObjectDisposedException ex)
                {
                    System.Diagnostics.Debug.Print(ex.Message);
                    return null;
                }
            }
            else
            {
                try
                {
                    reader = new Mp3FileReader(source);
                    inputStream = new WaveChannel32(reader as Mp3FileReader);
                }
                catch (ObjectDisposedException ex)
                {
                    System.Diagnostics.Debug.Print(ex.Message);
                    return null;
                }
            }

            return inputStream;
        }
    }
}
